package com.rongxun.base;

import android.support.annotation.NonNull;
import android.util.Log;

/**
 * 创建者     庄丰泽
 * 创建时间   2018/5/19 11:20
 * 描述
 */

public abstract class MvpFragment<V extends IBase.IView,P extends BasePresenter> extends BaseFragment implements MvpCallBack<V,P> {

    private P presenter;


    @NonNull
    @Override
    public abstract P createPresenter();

    @NonNull
    @Override
    public P getPresenter() {
        if (presenter == null) {
            presenter = createPresenter();
        }


        return presenter;
    }




    @Override
    public void setPresenter(@NonNull P presenter) {
        this.presenter = presenter;
    }


    @Override
    public V getMvpView() {
        return (V) this;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (presenter != null){
            presenter.release();

        }
        Log.d("onDestroy","onDestroy");
    }

}
